import axios from 'axios';
import { ElMessage } from "element-plus";


let loginApi = axios.create({
    // baseURL: 'http://10.82.11.45:9207/user/'
    // baseURL: 'http://' + document.location.hostname +':'+ window.location.port + "/user/"
    baseURL: import.meta.env.DEV?'http://10.248.219.71:207/user/':'http://' + document.location.hostname +':'+ window.location.port + "/user/"
})
loginApi.interceptors.request.use(config => {

    config.headers["token"] = localStorage.getItem("token")
    return config
})

loginApi.interceptors.response.use(res => {
    if (res.data["msg"] && res.data["tipElm"]) {
        ElMessage({
            message: res.data["tipElm"],
            type: 'success',
        })
    }else {
        if (res.data["tipElm"]) {
            ElMessage.error(res.data["tipElm"])
        }
    }
    return res.data
}, error => {
    console.log(error)
    ElMessage.error('服务器好像出错了')
    return false;
})

export default loginApi;